﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;
using WXYW.DAL;

namespace WXYW
{
    public partial class ApplicationListProductDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindProduct();
            }
        }

        private void BindProduct()
        {
            ApplicationService service = new ApplicationService();
            ApplicationForm applicationForm = service.GetApplicationFormDetailByID(long.Parse(Request.QueryString[Constants.QUERYSTR_APPLICATION_ID]));

            applyCompanyNameTxtBox.Text = applicationForm.User.CompanyName; //ContextService.CurrentAccount.CompanyName;
            mailAddressTxtBox.Text = applicationForm.User.UserAddress; //ContextService.CurrentAccount.UserAddress;
            applierEmailTxtBox.Text = applicationForm.User.UserEmail; //ContextService.CurrentAccount.UserEmail;
            applierFaxTxtBox.Text = applicationForm.User.UserFax; //ContextService.CurrentAccount.UserFax;
            rmaLabel.Text = applicationForm.ApplicationCode;
            runningNumberLabel.Text = applicationForm.RunningNumber;
            receiveLabel.Text = applicationForm.ReceiveDateTime.HasValue ? applicationForm.ReceiveDateTime.Value.ToString("yyyy-MM-dd") : "0000-00-00";
            //applierMobilePhoneTxtBox.Text = ContextService.CurrentAccount.UserMobilePhone;
            applierNameTxtBox.Text = applicationForm.User.ContactPerson; //ContextService.CurrentAccount.UserName;
            applierPhoneTxtBox.Text = applicationForm.User.UserPhone;//ContextService.CurrentAccount.UserPhone;

            productGridView.DataSource = applicationForm.ApplicationProduct;
            productGridView.DataBind();
        }

        protected void viewLinkButton_Click(object sender, EventArgs e)
        {
            string productID = ((LinkButton)sender).CommandArgument;
            Response.Redirect(string.Format("MaintainRecordDetail.aspx?{0}={1}", Constants.QUERYSTR_PRODUCT_ID, productID));
        }

        protected void backLinkButton_Click(object sender, EventArgs e)
        {
            string url = Request.QueryString[Constants.QUERYSTR_BACK_URL];
            if (url != null && !url.Equals(""))
            Response.Redirect(url);
        }
    }
}
